﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Model;
using System.Collections.Generic;
namespace DAL
{
    /// <summary>
    /// 数据访问类:PMS_ProjectMaintainFinance
    /// </summary>
    public class PMS_ProjectMaintainFinanceDAL
    {
        public PMS_ProjectMaintainFinanceDAL()
        { }
        #region  Method

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(PMS_ProjectMaintainFinance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into PMS_ProjectMaintainFinance(");
            strSql.Append("projectID,customerName,orderAmount,changeAmount,settlementAmount,startDate,endDate,systemACSCount,systemCCTVCount,systemALARMCount,systemATMCount,systemACSAmount,systemCCTVAmount,systemALARMAmount,systemATMAmount,paidMoney,claimMoney,balanceMoney,applyStage,remark)");
            strSql.Append(" values (");
            strSql.Append("@projectID,@customerName,@orderAmount,@changeAmount,@settlementAmount,@startDate,@endDate,@systemACSCount,@systemCCTVCount,@systemALARMCount,@systemATMCount,@systemACSAmount,@systemCCTVAmount,@systemALARMAmount,@systemATMAmount,@paidMoney,@claimMoney,@balanceMoney,@applyStage,@remark)");
            SqlParameter[] parameters = {
					new SqlParameter("@remark", SqlDbType.Text),
					new SqlParameter("@projectID", SqlDbType.NVarChar,50),
					new SqlParameter("@customerName", SqlDbType.NVarChar,100),
					new SqlParameter("@orderAmount", SqlDbType.Decimal,9),
					new SqlParameter("@changeAmount", SqlDbType.Decimal,9),
					new SqlParameter("@settlementAmount", SqlDbType.Decimal,9),
					new SqlParameter("@startDate", SqlDbType.DateTime),
					new SqlParameter("@endDate", SqlDbType.DateTime),
					new SqlParameter("@systemACSCount", SqlDbType.Int,4),
					new SqlParameter("@systemCCTVCount", SqlDbType.Int,4),
					new SqlParameter("@systemALARMCount", SqlDbType.Int,4),
					new SqlParameter("@systemATMCount", SqlDbType.Int,4),
					new SqlParameter("@systemACSAmount", SqlDbType.Decimal,9),
					new SqlParameter("@systemCCTVAmount", SqlDbType.Decimal,9),
					new SqlParameter("@systemALARMAmount", SqlDbType.Decimal,9),
					new SqlParameter("@systemATMAmount", SqlDbType.Decimal,9),
					new SqlParameter("@paidMoney", SqlDbType.Decimal,9),
					new SqlParameter("@claimMoney", SqlDbType.Decimal,9),
					new SqlParameter("@balanceMoney", SqlDbType.Decimal,9),
					new SqlParameter("@applyStage", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.remark;
            parameters[1].Value = model.projectID;
            parameters[2].Value = model.customerName;
            parameters[3].Value = model.orderAmount;
            parameters[4].Value = model.changeAmount;
            parameters[5].Value = model.settlementAmount;
            parameters[6].Value = model.startDate;
            parameters[7].Value = model.endDate;
            parameters[8].Value = model.systemACSCount;
            parameters[9].Value = model.systemCCTVCount;
            parameters[10].Value = model.systemALARMCount;
            parameters[11].Value = model.systemATMCount;
            parameters[12].Value = model.systemACSAmount;
            parameters[13].Value = model.systemCCTVAmount;
            parameters[14].Value = model.systemALARMAmount;
            parameters[15].Value = model.systemATMAmount;
            parameters[16].Value = model.paidMoney;
            parameters[17].Value = model.claimMoney;
            parameters[18].Value = model.balanceMoney;
            parameters[19].Value = model.applyStage;

            int rows = SqlHelper.ExecuteNonQuery(Comm.Config.PMS, CommandType.Text, strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PMS_ProjectMaintainFinance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PMS_ProjectMaintainFinance set ");
            strSql.Append("customerName=@customerName,");
            strSql.Append("orderAmount=@orderAmount,");
            strSql.Append("changeAmount=@changeAmount,");
            strSql.Append("settlementAmount=@settlementAmount,");
            strSql.Append("startDate=@startDate,");
            strSql.Append("endDate=@endDate,");
            strSql.Append("systemACSCount=@systemACSCount,");
            strSql.Append("systemCCTVCount=@systemCCTVCount,");
            strSql.Append("systemALARMCount=@systemALARMCount,");
            strSql.Append("systemATMCount=@systemATMCount,");
            strSql.Append("systemACSAmount=@systemACSAmount,");
            strSql.Append("systemCCTVAmount=@systemCCTVAmount,");
            strSql.Append("systemALARMAmount=@systemALARMAmount,");
            strSql.Append("systemATMAmount=@systemATMAmount,");
            strSql.Append("paidMoney=@paidMoney,");
            strSql.Append("claimMoney=@claimMoney,");
            strSql.Append("balanceMoney=@balanceMoney,");
            strSql.Append("applyStage=@applyStage,");
            strSql.Append("remark=@remark");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@remark", SqlDbType.Text),
					new SqlParameter("@customerName", SqlDbType.NVarChar,100),
					new SqlParameter("@orderAmount", SqlDbType.Decimal,9),
					new SqlParameter("@changeAmount", SqlDbType.Decimal,9),
					new SqlParameter("@settlementAmount", SqlDbType.Decimal,9),
					new SqlParameter("@startDate", SqlDbType.DateTime),
					new SqlParameter("@endDate", SqlDbType.DateTime),
					new SqlParameter("@systemACSCount", SqlDbType.Int,4),
					new SqlParameter("@systemCCTVCount", SqlDbType.Int,4),
					new SqlParameter("@systemALARMCount", SqlDbType.Int,4),
					new SqlParameter("@systemATMCount", SqlDbType.Int,4),
					new SqlParameter("@systemACSAmount", SqlDbType.Decimal,9),
					new SqlParameter("@systemCCTVAmount", SqlDbType.Decimal,9),
					new SqlParameter("@systemALARMAmount", SqlDbType.Decimal,9),
					new SqlParameter("@systemATMAmount", SqlDbType.Decimal,9),
					new SqlParameter("@paidMoney", SqlDbType.Decimal,9),
					new SqlParameter("@claimMoney", SqlDbType.Decimal,9),
					new SqlParameter("@balanceMoney", SqlDbType.Decimal,9),
					new SqlParameter("@applyStage", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.id;
            parameters[1].Value = model.remark;
            parameters[2].Value = model.customerName;
            parameters[3].Value = model.orderAmount;
            parameters[4].Value = model.changeAmount;
            parameters[5].Value = model.settlementAmount;
            parameters[6].Value = model.startDate;
            parameters[7].Value = model.endDate;
            parameters[8].Value = model.systemACSCount;
            parameters[9].Value = model.systemCCTVCount;
            parameters[10].Value = model.systemALARMCount;
            parameters[11].Value = model.systemATMCount;
            parameters[12].Value = model.systemACSAmount;
            parameters[13].Value = model.systemCCTVAmount;
            parameters[14].Value = model.systemALARMAmount;
            parameters[15].Value = model.systemATMAmount;
            parameters[16].Value = model.paidMoney;
            parameters[17].Value = model.claimMoney;
            parameters[18].Value = model.balanceMoney;
            parameters[19].Value = model.applyStage;

            int rows = SqlHelper.ExecuteNonQuery(Comm.Config.PMS, CommandType.Text, strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PMS_ProjectMaintainFinance set isDelete='1' where id=@id");
            SqlParameter[] parameters = { new SqlParameter("@id", id) };

            int rows = SqlHelper.ExecuteNonQuery(Comm.Config.PMS, CommandType.Text, strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PMS_ProjectMaintainFinance GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select a.*,b.city FROM PMS_ProjectMaintainFinance as a
left join PMS_Project as b on a.projectID=b.id
where a.isDelete='0' and a.id=@id");
            SqlParameter[] values = { new SqlParameter("@id", id) };
            return SqlHelper.GetDataByColumns<PMS_ProjectMaintainFinance>(Comm.Config.PMS, strSql.ToString(), values);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<PMS_ProjectMaintainFinance> GetList(string projectID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select a.*,b.city FROM PMS_ProjectMaintainFinance as a
left join PMS_Project as b on a.projectID=b.id
where a.isDelete='0' and a.projectID=@projectID");
            SqlParameter[] values = { new SqlParameter("@projectID", projectID) };
            return SqlHelper.GetDataByColumnsLst<PMS_ProjectMaintainFinance>(Comm.Config.PMS, strSql.ToString(), values);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<PMS_ProjectMaintainFinance> GetList(PMS_ProjectMaintainFinanceQuery query)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select a.*,b.city FROM PMS_ProjectMaintainFinance as a
left join PMS_Project as b on a.projectID=b.id
where a.isDelete='0' and a.projectID=@projectID ");
            if (query.startDate != null && query.startDate != DateTime.MinValue)
            {
                strSql.Append(" and a.startDate>='" + query.startDate + "' ");
            }
            if (query.endDate != null && query.endDate != DateTime.MinValue)
            {
                strSql.Append(" and a.startDate<='" + query.endDate + "' ");
            }
            SqlParameter[] values = { new SqlParameter("@projectID", query.projectID) };
            return SqlHelper.GetDataByColumnsLst<PMS_ProjectMaintainFinance>(Comm.Config.PMS, strSql.ToString(), values);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataTable GetListTable(PMS_ProjectMaintainFinanceQuery query)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select projectIDS=b.projectID,b.projectName,b.city,a.* FROM PMS_ProjectMaintainFinance as a
left join PMS_Project as b on a.projectID=b.id
where a.isDelete='0' and a.projectID=@projectID ");
            if (query.startDate != null && query.startDate != DateTime.MinValue)
            {
                strSql.Append(" and a.startDate>='" + query.startDate + "' ");
            }
            if (query.endDate != null && query.endDate != DateTime.MinValue)
            {
                strSql.Append(" and a.startDate<='" + query.endDate + "' ");
            }
            SqlParameter[] values = { new SqlParameter("@projectID", query.projectID) };
            return SqlHelper.ExecuteGetTable(Comm.Config.PMS, CommandType.Text, strSql.ToString(), values);
        }

        #endregion  Method
    }
}

